import threading
import ipaddress
from concurrent.futures import ThreadPoolExecutor
from queue import Queue

def check_ip_is_master_station(ip):
    # 原检查主站的函数代码
    pass

def worker(queue):
    while not queue.empty():
        ip = queue.get()
        if check_ip_is_master_station(ip):
            print(f"主站IP: {ip}")
            # 或者在这里进行其他操作，比如保存到文件等
    
def find_master_station_ips(base_ip, gateway, netmask):
    network = ipaddress.ip_network(f"{base_ip}/{netmask}", strict=False)
    queue = Queue()
    for ip in network.hosts():
        queue.put(str(ip))

    threads = []
    thread_count = 5  # 设置线程数
    for _ in range(thread_count):
        t = threading.Thread(target=worker, args=(queue,))
        t.start()
        threads.append(t)

    for t in threads:
        t.join()

if __name__ == "__main__":
    base_ip = "192.168.31.0"  # 基站IP
    gateway = "192.168.31.1"  # 网关IP
    netmask = "24"  # 子网掩码位数
    find_master_station_ips(base_ip, gateway, netmask)